package com.maila.calltaxi_driver.ui;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.view.Gravity;
import android.view.View;
import android.widget.ListView;
import android.widget.PopupWindow;
import android.widget.RadioButton;
import android.widget.Toast;

import com.maila.calltaxi_driver.R;
import com.maila.calltaxi_driver.adapter.HallOrderAdapter;
import com.maila.calltaxi_driver.adapter.HomeOrderAdapter;
import com.maila.calltaxi_driver.data.Order;
import com.maila.calltaxi_driver.utils.StatusBarUtil;
import com.maila.calltaxi_driver.view.PushOrderPop;
import com.zhy.autolayout.AutoLinearLayout;
import com.zhy.autolayout.AutoRelativeLayout;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Administrator on 2017/6/27.
 */

public class OrderHallActivity extends AppCompatActivity implements View.OnClickListener {


    AutoRelativeLayout returnIv;

    RadioButton rbHall;

    RadioButton rbMyorder;

    ListView lvMallOrder;

    AutoLinearLayout btnStop;
    HallOrderAdapter hallorderAdapter;
    HomeOrderAdapter homeOrderAdapter;
    List<Order> mdata = new ArrayList<>();
    List<Order> mdata1 = new ArrayList<>();
    int flag = 1;
    Order order;
    PushOrderPop pushWinDialog;
    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_orderhall);
        StatusBarUtil.setColorNoTranslucent(this,getResources().getColor(R.color.colorPrimaryDark));
        order= new Order();
        initView();
        initData();
    }

    private void initdata() {
        Order order1 = new Order();
        order1.setType(1);
        order1.setPositions("潍坊信息职业学院");
        order1.setStatus("现在去接乘客");
        Order order2 = new Order();
        order2.setType(0);
        order2.setPositions("潍坊市高新区人民广场");
        order2.setStatus("明天下午3:50去上车点接乘客");
        mdata.add(order1);
        mdata.add(order2);

        Order order3 = new Order();
        order3.setType(1);
        order3.setPositions("潍坊信息职业学院");
        order3.setStatus("距您约13公里");
        Order order4 = new Order();
        order4.setType(0);
        order4.setPositions("潍坊市高新区人民广场");
        order4.setStatus("距您约15公里");
        Order order5 = new Order();
        order5.setType(0);
        order5.setPositions("潍坊市广播电视台大厦");
        order5.setStatus("距您约17公里");
        mdata1.add(order3);
        mdata1.add(order4);
        mdata1.add(order5);
    }

    private void initview() {
        hallorderAdapter = new HallOrderAdapter(this);
        homeOrderAdapter = new HomeOrderAdapter(this);
        updatastatus();

    }

    private void updatastatus() {
        if (flag == 1) {
            lvMallOrder.setAdapter(hallorderAdapter);
        } else {
            lvMallOrder.setAdapter(homeOrderAdapter);
        }
    }


    public void initView() {
        returnIv = (AutoRelativeLayout) findViewById(R.id.return_iv);
        btnStop = (AutoLinearLayout) findViewById(R.id.btn_stop);
        rbHall = (RadioButton) findViewById(R.id.rb_hall);
        rbMyorder = (RadioButton) findViewById(R.id.rb_myorder);

        returnIv.setOnClickListener(this);
        btnStop.setOnClickListener(this);
        rbHall.setOnClickListener(this);
        rbMyorder.setOnClickListener(this);
        lvMallOrder = (ListView) findViewById(R.id.lv_mall_order);
        initview();
    }


    public void initData() {
        initdata();
        hallorderAdapter.setDatas(mdata1);
        homeOrderAdapter.setDatas(mdata);
    }


    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.return_iv:
                finish();
                break;
            case R.id.rb_hall:
                flag = 1;
                rbHall.setChecked(true);
                rbMyorder.setChecked(false);
                updatastatus();

                order.setType(0);
                order.setPositions("潍坊市广播电视台大厦");
                order.setData("7月13日 9:00");
                order.setStatus("距您约17公里");
                pushWinDialog=new PushOrderPop(this,order);
                pushWinDialog.showAtLocation(getWindow().getDecorView(), Gravity.CENTER,0,0);
                pushWinDialog.setOnDismissListener(new PopupWindow.OnDismissListener() {
                    @Override
                    public void onDismiss() {
                        // TODO: 2017/6/30  
                        Toast.makeText(OrderHallActivity.this,"列表已更新",Toast.LENGTH_SHORT).show();
                    }
                });
                break;
            case R.id.rb_myorder:
                flag = 2;
                rbHall.setChecked(false);
                rbMyorder.setChecked(true);
                updatastatus();
                break;
            case R.id.btn_stop:
                Toast.makeText(this, "已取消听单", Toast.LENGTH_SHORT).show();
                finish();
                break;
        }
    }
}
